﻿$(function() {
    if (top.location != self.location) {
        top.location = self.location;
    } else {
        login.init();
        Utils.textBoxsOnEnter(login._login);
    }
});


var login =
{
    init: function() {
        $("#btnLogin").click(this._login);
        $("#panellogin").center('1/3');
        $("#panellogin").show();
        $("#username").focus();
        var _u = $.query.get('u').toString();
        if (_u.length > 0) {
            $("#username").val(_u);
            $("#password").focus();
        }
    },
    _login: function() {
        var id = $("#username").val();
        var pwd = $("#password").val();
        var vy = $("#verify").val();

        if (id.length === 0) {
            utility.showPopUp(m.Err0001, 1, function() { $("#username").focus(); });
        }
        else if (pwd.length === 0) {
            utility.showPopUp(m.Err0002, 1, function() { $("#password").focus(); });
        }
        else {
            var param = { username: id, password: pwd, verify: vy };
            utility.service("LoginService/BouLogin", param, "POST", function(data) {
                if (data.code > 0) {
                    var redirto = utility.getRedirUrl('Bou', 'Index') + '?' + (new Date()).getMilliseconds();
                    window.location.href = redirto;
                } else {
                    utility.showPopUp(data.msg, 1, function() { window.location.href = window.location.pathname + '?u=' + id; });
                }
            });
        }
    }
};